<?php
class Hopdong_Model_Doanhthu extends Zend_Db_Table{
	
	protected $_name = 'nam_hopdong';
	protected $_primary ='id';
	
	protected $_ids;
	
	public function getItem($arrParam = null, $options = null){
		
		if($options['task'] == 'admin-info' || $options['task'] == 'admin-edit'){
			$db = Zend_Registry::get('connectDb');
			//$db = Zend_Db::factory($adapter, $config);
			$select = $db->select()
			->from('khuyenmai AS km',array("*","DATE_FORMAT(km.ngaybatdau,'%d/%m/%Y %h:%i:%s') AS ngaybatdau","DATE_FORMAT(km.ngayketthuc,'%d/%m/%Y  %h:%i:%s') AS ngayketthuc"))
			->joinLeft('users AS u', 'km.modified_by = u.id',array('u.user_name AS name_modified_by'))
			->where('km.id = ?', $arrParam['id'], INTEGER);
			//echo $select;die;	
			$result = $db->fetchRow($select);
		}
		 
		if($options['task'] == 'info-nhanvien'){
			$db = Zend_Registry::get('connectDb');
			//$db = Zend_Db::factory($adapter, $config);
			$select = $db	-> select()
							-> from('users AS u',array('u.name AS name_nhanvien','u.user_name AS user_name','u.email AS email'))
							-> joinLeft('phongban AS pb', 'u.id_phongban = pb.id',array('pb.name AS name_phongban'))
							-> where('u.id = ?', $arrParam['id']);
			//echo $select;die;
			$result = $db	->fetchRow($select);
		}
		return $result;
	}
	
	public function countItem($arrParam = null, $options = null){
		$ssFilter  = $arrParam['ssFilter'];
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter, $config);
		
		$quyen_nv = new Zendvn_System_Info();
		$quyen_nhom = $quyen_nv->getGroupInfo('permission');
		$quyen_info = $quyen_nv->getInfo();
		$quyen_member = $quyen_nv->getMemberInfo();
		$quyen_phongban = $quyen_nv->getPhongbanInfo();
		
		if($options == null){
			$select = $db	->	select()
							->	from('khuyenmai AS c', array('COUNT(c.id) AS totalItem'));
			$result = $db->fetchOne($select);
		}
		
		if($options['task'] == 'admin-doanhthu'){
			$ssFilter  = $arrParam['ssFilter'];
				
			$date = new Zend_Date();
			$dateThangNay = $date->toString('YYYY-MM');
			$select = $db	->	select()
// 							->	from('nam_hopdong AS hd',array("id"))
// 				 			->	joinLeft('users AS u', 'hd.id_nhanvien = u.id',array('u.name AS name_nhanvien','u.user_name AS user_name'))
// 							->	joinLeft('phongban AS pb', 'u.id_phongban = pb.id',array('pb.name AS name_phongban'))
							//->	columns('SUM(hd_dongia) AS hd_dongia')
							//->	columns('SUM(hd_thanhtien) AS hd_thanhtien')
							//->	columns('SUM(hd_sotiendadong) AS hd_sotiendadong')
							//->	columns('SUM(hd_sotienno) AS hd_sotienno')
// 							->	group('u.id');
			
			
							->	from('nam_hopdong AS hd',array("*"))
							->	joinLeft('users AS u', 'hd.id_nhanvien = u.id',array('u.name AS name_nhanvien','u.user_name AS user_name'))
							//->	joinLeft('phongban AS pb', 'u.id_phongban = pb.id',array('pb.name AS name_phongban'))
							//->	columns('SUM(hd_dongia) AS hd_dongia')
							//->	columns('SUM(hd_thanhtien) AS hd_thanhtien')
							//->	columns('SUM(hd_sotiendadong) AS hd_sotiendadong')
							//->	columns('SUM(hd_sotienno) AS hd_sotienno')
							->	group('u.id')
							-> where('hd.status = ?',1);
							
			if (!empty($ssFilter['keywords'])) {
				$select->where("(u.name LIKE '%" . $ssFilter['keywords'] . "%')");
			}
			
			if (!empty($ssFilter['tungay'])) {
					
				$date = new Zend_Date();
				$date->set($ssFilter['tungay']);
				$tungay = $date->toString('YYYY-MM-dd');
				$select->where("DATEDIFF(hd.ngayky,'".$tungay."') >= 0");
					
			}
				
			if (!empty($ssFilter['denngay'])) {
				$date2 = new Zend_Date();
				$date2->set($ssFilter['denngay']);
				$denngay = $date2->toString('YYYY-MM-dd');
				$select->where("DATEDIFF(hd.ngayky,'".$denngay."') <= 0");
					
			}
			
			if (!empty($ssFilter['id_phongban'])) {
				$select_category = $db 	-> select()
										-> from('phongban',array('id','name','parents'))
										-> where('status = ?',1);
				$resultCategory = $db->fetchAll($select_category);
			
				$system = new Zendvn_System_Recursive($resultCategory);
				$newArray = $system->builArray($ssFilter['id_phongban']);
				$tmp[] = $ssFilter['id_phongban'];
				if (count($newArray)>0) {
					foreach ($newArray as $key => $val) {
						$tmp[] = $val['id'];
					}
				}
				$ids = implode(',', $tmp);
			
				$selectUser	= $db	->	select()
									->	from('users AS u', array('id'))
									->	where('u.id_phongban IN(' . $ids . ')');
				$resultUser = $db	->	fetchCol($selectUser);
					
				if(count($resultUser) > 0) {
					$idUser = implode(',', $resultUser);
				} else {
					$idUser = 0;
				}
			
				$select->where('hd.id_nhanvien IN(' . $idUser . ')');
			} else {
				if($quyen_nhom == 'Limit Access') {
					$select_category = $db	->	select()
											->	from('phongban AS pb', array('id','name','parents'));
						
					$resultCategory = $db	->	fetchAll($select_category);
						
					$system = new Zendvn_System_Recursive($resultCategory);
					$newArray = $system->builArray($quyen_phongban['id']);
					$tmp[] = $quyen_phongban['id'];
					if (count($newArray)>0) {
						foreach ($newArray as $key => $val) {
							$tmp[] = $val['id'];
						}
					}
					$ids = implode(',', $tmp);
						
					$selectUser	= $db	->	select()
										->	from('users AS u', array('id'))
										->	where('u.id_phongban IN(' . $ids . ')');
					$resultUser = $db	->	fetchCol($selectUser);
						
					if(count($resultUser) > 0) {
						$idUser = implode(',', $resultUser);
					} else {
						$idUser = 0;
					}
						
					$select->where('hd.id_nhanvien IN(' . $idUser . ')');
				}
			}
				
			if (!empty($ssFilter['id_nhanvien'])) {
				$select->where('hd.id_nhanvien = ?', $ssFilter['id_nhanvien']);
			}
			
// 			if (!empty($ssFilter['date_nam'])) {
// 				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $ssFilter['date_nam'] . "'");
// 			} else {
// 				$date = new Zend_Date();
// 				$dateNamnay = $date->toString('YYYY');
// 				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $dateNamnay . "'");
// 			}
			
// 			if (isset($ssFilter['date_thang'])) {
// 				if ($ssFilter['date_thang'] != 0) {
// 					$select->where("DATE_FORMAT(hd.ngayky,'%m') = ?", $ssFilter['date_thang']);
// 				}
// 			} else {
// 				$date = new Zend_Date();
// 				$dateThangnay = $date->toString('MM');
// 				$select->where("DATE_FORMAT(hd.ngayky,'%m') = ?", $dateThangnay);
// 			}
			$result = $db->fetchAll($select);
			
		}
	
		if($options['task'] == 'admin-list'){
			$db = Zend_Registry::get('connectDb');
			//$db = Zend_Db::factory($adapter, $config);
			
			$select = $db	->	select()
							->	from('khuyenmai AS c', array('COUNT(c.id) AS totalItem'));
			if(!empty($ssFilter['keywords'])){
				$keywords = '%' . $ssFilter['keywords'] . '%';
				$select->where('c.name LIKE ?', $keywords, STRING);
			}
			
			$result = $db->fetchOne($select);
		}
		
		return $result;
	}
	
	public function itemInSelectbox($arrParam = null, $options = null){
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter, $config);
		$ssFilter  = $arrParam['ssFilter'];
		if($options == null){
			$select = $db	->	select()
							->	from('phongban AS cc',array('id','name','status'))
							->	order('cc.id ASC');
			$result = $db->fetchPairs($select);
			
		}
		return $result;
	}
	
	public function userInSelectbox($arrParam = null, $options = null){
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter, $config);
		$ssFilter  = $arrParam['ssFilter'];
		if($options == null){
			$select = $db	->	select()
							->	from('users AS cc',array('id','name','status'))
							->	order('cc.id ASC');
			$result = $db->fetchPairs($select);
		}
		return $result;
	}
	
	public function listItem($arrParam = null, $options = null){
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter, $config);
		$ssFilter  = $arrParam['ssFilter'];
		
		$quyen_nv = new Zendvn_System_Info();
		$quyen_nhom = $quyen_nv->getGroupInfo('permission');
		$quyen_info = $quyen_nv->getInfo();
		$quyen_member = $quyen_nv->getMemberInfo();
		$quyen_phongban = $quyen_nv->getPhongbanInfo();
		
		if($options['task'] == 'admin-list'){
			$paginator = $arrParam['paginator'];
			
			$date = new Zend_Date();
			$dateThangNay = $date->toString('YYYY-MM');
			$select = $db	->	select()
							->	from('nam_hopdong AS hd',array("*"))
				 			->	joinLeft('users AS u', 'hd.id_nhanvien = u.id',array('u.name AS name_nhanvien','u.user_name AS user_name'))
							->	joinLeft('phongban AS pb', 'u.id_phongban = pb.id',array('pb.name AS name_phongban'))
							->	columns('SUM(hd_dongia) AS hd_dongia')
							->	columns('SUM(hd_thanhtien) AS hd_thanhtien')
							->	columns('SUM(hd_sotiendadong) AS hd_sotiendadong')
							->	columns('SUM(hd_sotienno) AS hd_sotienno')
							->	group('u.id')
							-> where('hd.status = ?',1);
							
			if($paginator['itemCountPerPage'] > 0){
				$page = $paginator['currentPage'];
				$rowCount = $paginator['itemCountPerPage'];
				$select->limitPage($page, $rowCount);
			}
			
			if (!empty($ssFilter['keywords'])) {
				$select->where("(u.name LIKE '%" . $ssFilter['keywords'] . "%')");
			}
			
			if (!empty($ssFilter['tungay'])) {
					
				$date = new Zend_Date();
				$date->set($ssFilter['tungay']);
				$tungay = $date->toString('YYYY-MM-dd');
				$select->where("DATEDIFF(hd.ngayky,'".$tungay."') >= 0");
					
			}
				
			if (!empty($ssFilter['denngay'])) {
				$date2 = new Zend_Date();
				$date2->set($ssFilter['denngay']);
				$denngay = $date2->toString('YYYY-MM-dd');
				$select->where("DATEDIFF(hd.ngayky,'".$denngay."') <= 0");
					
			}
			
			if (!empty($ssFilter['id_phongban'])) {
				$select_category = $db 	-> select()
										-> from('phongban',array('id','name','parents'))
										-> where('status = ?',1);
				$resultCategory = $db->fetchAll($select_category);
			
				$system = new Zendvn_System_Recursive($resultCategory);
				$newArray = $system->builArray($ssFilter['id_phongban']);
				$tmp[] = $ssFilter['id_phongban'];
				if (count($newArray)>0) {
					foreach ($newArray as $key => $val) {
						$tmp[] = $val['id'];
					}
				}
				$ids = implode(',', $tmp);
			
				$selectUser	= $db	->	select()
									->	from('users AS u', array('id'))
									->	where('u.id_phongban IN(' . $ids . ')');
				$resultUser = $db	->	fetchCol($selectUser);
					
				if(count($resultUser) > 0) {
					$idUser = implode(',', $resultUser);
				} else {
					$idUser = 0;
				}
			
				$select->where('hd.id_nhanvien IN(' . $idUser . ')');
			} else {
				if($quyen_nhom == 'Limit Access') {
					$select_category = $db	->	select()
											->	from('phongban AS pb', array('id','name','parents'));
						
					$resultCategory = $db	->	fetchAll($select_category);
						
					$system = new Zendvn_System_Recursive($resultCategory);
					$newArray = $system->builArray($quyen_phongban['id']);
					$tmp[] = $quyen_phongban['id'];
					if (count($newArray)>0) {
						foreach ($newArray as $key => $val) {
							$tmp[] = $val['id'];
						}
					}
					$ids = implode(',', $tmp);
						
					$selectUser	= $db	->	select()
										->	from('users AS u', array('id'))
										->	where('u.id_phongban IN(' . $ids . ')');
					$resultUser = $db	->	fetchCol($selectUser);
						
					if(count($resultUser) > 0) {
						$idUser = implode(',', $resultUser);
					} else {
						$idUser = 0;
					}
						
					$select->where('hd.id_nhanvien IN(' . $idUser . ')');
				}
			}
				
			if (!empty($ssFilter['id_nhanvien'])) {
				$select->where('hd.id_nhanvien = ?', $ssFilter['id_nhanvien']);
			}
			
// 			if (!empty($ssFilter['date_nam'])) {
// 				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $ssFilter['date_nam'] . "'");
// 			} else {
// 				$date = new Zend_Date();
// 				$dateNamnay = $date->toString('YYYY');
// 				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $dateNamnay . "'");
// 			}
			
// 			if (isset($ssFilter['date_thang'])) {
// 				if ($ssFilter['date_thang'] != 0) {
// 					$select->where("DATE_FORMAT(hd.ngayky,'%m') = ?", $ssFilter['date_thang']);
// 				}
// 			} else {
// 				$date = new Zend_Date();
// 				$dateThangnay = $date->toString('MM');
// 				$select->where("DATE_FORMAT(hd.ngayky,'%m') = ?", $dateThangnay);
// 			}
			//echo $select;die;
			
			$result = $db->fetchAll($select);
		}
		
		
		
		if($options['task'] == 'admin-excel'){
			$paginator = $arrParam['paginator'];
				
			$date = new Zend_Date();
			$dateThangNay = $date->toString('YYYY-MM');
			$select = $db	->	select()
			->from('nam_hopdong AS hd',array("*"))
			->joinLeft('users AS u', 'hd.id_nhanvien = u.id',array('u.name AS name_nhanvien','u.user_name AS user_name'))
			->joinLeft('phongban AS pb', 'u.id_phongban = pb.id',array('pb.name AS name_phongban'))
			->columns('SUM(hd_dongia) AS hd_dongia')
			->columns('SUM(hd_thanhtien) AS hd_thanhtien')
			->columns('SUM(hd_sotiendadong) AS hd_sotiendadong')
			->columns('SUM(hd_sotienno) AS hd_sotienno')
			//->where("DATE_FORMAT(hd.ngayky,'%Y-%m') = '".$dateThangNay."'")
			->group('u.id')
			-> where('hd.status = ?',1);
				
			//echo $select;die;
			if($paginator['itemCountPerPage'] > 0){
				$page = $paginator['currentPage'];
				$rowCount = $paginator['itemCountPerPage'];
				$select->limitPage($page, $rowCount);
			}
				
			if (!empty($ssFilter['keywords'])) {
				$select->where("(u.name LIKE '%" . $ssFilter['keywords'] . "%')");
			}
			
			if (!empty($ssFilter['tungay'])) {
					
				$date = new Zend_Date();
				$date->set($ssFilter['tungay']);
				$tungay = $date->toString('YYYY-MM-dd');
				$select->where("DATEDIFF(hd.ngayky,'".$tungay."') >= 0");
					
			}
				
			if (!empty($ssFilter['denngay'])) {
				$date2 = new Zend_Date();
				$date2->set($ssFilter['denngay']);
				$denngay = $date2->toString('YYYY-MM-dd');
				$select->where("DATEDIFF(hd.ngayky,'".$denngay."') <= 0");
					
			}
				
				
			if (!empty($ssFilter['id_phongban'])) {
				$select_category = $db 	-> select()
				-> from('phongban',array('id','name','parents'))
				-> where('status = ?',1);
				$resultCategory = $db->fetchAll($select_category);
					
				$system = new Zendvn_System_Recursive($resultCategory);
				$newArray = $system->builArray($ssFilter['id_phongban']);
				$tmp[] = $ssFilter['id_phongban'];
				if (count($newArray)>0) {
					foreach ($newArray as $key => $val) {
						$tmp[] = $val['id'];
					}
				}
					
				$ids = implode(',', $tmp);
				$select->where('u.id_phongban IN(' . $ids . ')');
			}
		
			if (!empty($ssFilter['id_nhanvien'])) {
				$select->where('hd.id_nhanvien = ?', $ssFilter['id_nhanvien']);
			}
				
// 			if (!empty($ssFilter['date_nam'])) {
// 				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $ssFilter['date_nam'] . "'");
// 			} else {
// 				$date = new Zend_Date();
// 				$dateNamnay = $date->toString('YYYY');
// 				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $dateNamnay . "'");
// 			}
				
// 			if (isset($ssFilter['date_thang'])) {
// 				if ($ssFilter['date_thang'] != 0) {
// 					$select->where("DATE_FORMAT(hd.ngayky,'%m') = ?", $ssFilter['date_thang']);
// 				}
// 			} else {
// 				$date = new Zend_Date();
// 				$dateThangnay = $date->toString('MM');
// 				$select->where("DATE_FORMAT(hd.ngayky,'%m') = ?", $dateThangnay);
// 			}
			//echo $select;die;
				
			$result = $db->fetchAll($select);
		}
		
		
		return $result;
	}
	
	
	public function info($arrParam = null, $options = null){
		//echo $arrParam['id'];die;
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter, $config);
		$ssFilter  = $arrParam['ssFilter'];
		if($options['task'] == 'admin-list'){
			$paginator = $arrParam['paginator'];
				
			
			
// 			SELECT SUM(hd_dongia) AS hd_dongia,SUM(hd_thanhtien) AS hd_thanhtien,SUM(hd_sotiendadong) AS hd_sotiendadong,SUM(hd_sotienno) AS hd_sotienno, MONTH(ngayky)
// 			FROM nam_hopdong
// 			WHERE id_nhanvien= 33
// 			GROUP BY MONTH(ngayky)
				
				
			
			$date = new Zend_Date();
			$dateThangNay = $date->toString('YYYY-MM');
			$select = $db	->	select()
			->from('nam_hopdong AS hd',array('MONTH(ngayky) AS ngayky', 'id_nhanvien AS id_nhanvien','SUM(hd_dongia) AS hd_dongia','SUM(hd_thanhtien) AS hd_thanhtien','SUM(hd_sotiendadong) AS hd_sotiendadong','SUM(hd_sotienno) AS hd_sotienno'))
			->joinLeft('users AS u', 'hd.id_nhanvien = u.id',array('u.name AS name_nhanvien','u.email AS email_nhanvien','u.user_name AS user_name'))
			->joinLeft('phongban AS pb', 'u.id_phongban = pb.id',array('pb.name AS name_phongban'))
			->where("hd.id_nhanvien = '".$arrParam['id']."'")
			->group('MONTH(hd.ngayky)')
			-> where('hd.status = ?',1);
				
			//echo $select;die;
			if($paginator['itemCountPerPage'] > 0){
				$page = $paginator['currentPage'];
				$rowCount = $paginator['itemCountPerPage'];
				$select->limitPage($page, $rowCount);
			}
				
			

			if (!empty($ssFilter['date_nam'])) {
				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $ssFilter['date_nam'] . "'");
			} else {
				$date = new Zend_Date();
				$dateNamnay = $date->toString('YYYY');
				$select->where("DATE_FORMAT(hd.ngayky,'%Y') = '" . $dateNamnay . "'");
			}
				


			//echo $select;
				
			$result = $db->fetchAssoc($select);
		}
	
		return $result;
	
	}

	public function saveItem($arrParam = null, $options = null){
		//var_dump($arrParam);die;
		if($options['task'] == 'admin-add'){
			$row 					= $this->fetchNew();
			$info 					= new Zendvn_System_Info();
			$createby 				= $info->getMemberInfo('id');

			$row->name 				= stripslashes($arrParam['name']);
			$row->giagiam 			= stripslashes($arrParam['giagiam']);
			$row->phantram 			= stripslashes($arrParam['phantram']);
			$row->content			= stripslashes($arrParam['content']);
			
			$giobatdau 				=stripslashes($arrParam['gio_tu']).':'.stripslashes($arrParam['phut_tu']).':'.stripslashes($arrParam['giay_tu']);
			$gioketthuc 			=stripslashes($arrParam['gio_den']).':'.stripslashes($arrParam['phut_den']).':'.stripslashes($arrParam['giay_den']);
			
			
			$date     = new Zend_Date();
			$date->set($arrParam['ngaybatdau']);
			$ngaybatdau    = $date->toString('YYYY-MM-dd');
			$row->ngaybatdau 			= $ngaybatdau . ' ' . $giobatdau;
			//echo $arrParam['ngayketthuc'];echo $gioketthuc;die;
			$date     = new Zend_Date();
			$date->set($arrParam['ngayketthuc']);
			$ngayketthuc    = $date->toString('YYYY-MM-dd');
			///echo $ngayketthuc;die;
			$row->ngayketthuc 			= $ngayketthuc.' '.$gioketthuc;
			
			
			$row->created 			= @date("Y-m-d h:i:s");
			$row->modified 			= @date("Y-m-d h:i:s");
			$row->created_by		= $createby;
			$row->modified_by		= $createby;
			
			
			$row->save();
		}
	
		if($options['task'] == 'admin-edit'){
				
			$where 				= ' id=' . $arrParam['id'];
			$row 				= $this->fetchRow($where);
		
			$info 					= new Zendvn_System_Info();
			$createby 			= $info->getMemberInfo('id');

			$row->name 			= stripslashes($arrParam['name']);
			$row->giagiam 			= stripslashes($arrParam['giagiam']);
			$row->phantram 			= stripslashes($arrParam['phantram']);
			$row->content			= stripslashes($arrParam['content']);
			
			$giobatdau 				=stripslashes($arrParam['gio_tu']).':'.stripslashes($arrParam['phut_tu']).':'.stripslashes($arrParam['giay_tu']);
			$gioketthuc 			=stripslashes($arrParam['gio_den']).':'.stripslashes($arrParam['phut_den']).':'.stripslashes($arrParam['giay_den']);
			
			//echo $arrParam['ngaybatdau'];die;
			$date     = new Zend_Date();
			$date->set($arrParam['ngaybatdau']);
			$ngaybatdau    = $date->toString('YYYY-MM-dd');
			
			//echo $ngaybatdau;die;
			$row->ngaybatdau 			= $ngaybatdau . ' ' . $giobatdau;
			
			$ngayketthuc     = new Zend_Date();
			$ngayketthuc->set($arrParam['ngayketthuc']);
			$ngayketthuc    = $ngayketthuc->toString('YYYY-MM-dd');
			//echo $ngayketthuc;echo $gioketthuc;die;
			$row->ngayketthuc 			= $ngayketthuc.' '.$gioketthuc;
			
			
			//$row->created 			= @date("Y-m-d h:i:s");
			$row->modified 			= @date("Y-m-d h:i:s");
			//$row->created_by		= $createby;
			$row->modified_by		= $createby;
			
			
			$row->save();
			$row->save();
		}
		
		if($options['task'] == 'public-hits'){
			$where 				= ' id=' . $arrParam['id'];
			$row 				= $this->fetchRow($where);
			
			$row->hits 		= $arrParam['hits'] + 1;
			
			$row->save();
		}
	}

	public function deleteItem($arrParam = null, $options = null){
		if($options['task'] == 'admin-delete'){				
			$where = ' id=' . $arrParam['id'];
			$result = $this->delete($where);
		}
	
		if($options['task'] == 'admin-delete-muti'){
			$cid = explode(',', $arrParam['cid']);
			if(!empty($cid) && isset($arrParam['cid'])){
				$ids = implode(',', $cid);
				$where = 'id IN (' . $ids . ')';
				$this->delete($where);
			}
	
		}
	}
	
	public function changeStatus($arrParam = null, $options = null){
		$cid = $arrParam['cid'];
		if(count($cid) > 0){
			if($arrParam['type'] == 1){
				$status = 1;
			}else{
				$status = 0;
			}
	
			$id = implode(',', $cid);
			$data = array('status' => $status);
			$where = 'id IN (' . $id . ')';
			$this->update($data, $where);
		}
		if($arrParam['id'] > 0){
			if($arrParam['type'] == 1){
				$status = 1;
			}else{
				$status = 0;
			}
			$data = array('status' => $status);
			$where = 'id = ' . $arrParam['id'];
			$this->update($data, $where);
		}
	}
	
	public function sortItem($arrParam = null, $options = null){
		$cid = $arrParam['cid'];
		$order = $arrParam['order'];
		if($options['task'] == 'admin-sort'){
			if(count($cid) > 0){
				foreach ($cid as $key => $val){
					$data = array('order' => $order[$val]);
					$where = 'id = ' . $val;
					$this->update($data, $where);
				}
			}
		}
	}
}